package com.wx.Exception;

import com.wx.Result.Result;
import com.wx.Result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
 
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public Result<ResultCodeEnum> handleCustomException(SystemException e) {
        // 可以根据需要自定义返回的响应体和状态码
        log.error("自定义数据异常:{}", e.getMsg());
        return Result.fail(e.getCode(),e.getMsg());
    }
    @ExceptionHandler(Exception.class)
    public Result<ResultCodeEnum> Exception(Exception e) {
        // 可以根据需要自定义返回的响应体和状态码
        log.error("全局异常:{}", e.getMessage());
        return Result.fail(ResultCodeEnum.SYSTEM_ERROR);
    }

    

}